﻿namespace Attacher
{
	internal class MainWindowViewModelInitializer : IMainWindowViewModelInitializer
	{
		#region Attributes

		private readonly IAttacherAutoStartService attacherAutoStartManager;

		#endregion

		public MainWindowViewModelInitializer(IAttacherAutoStartService attacherAutoStartManager)
		{
			ParameterChecker.IsNotNull(attacherAutoStartManager, "attacherAutoStartManager");

			this.attacherAutoStartManager = attacherAutoStartManager;
		}

		public void Initialize(MainWindowViewModel mainWindowViewModel)
		{
            ParameterChecker.IsNotNull(mainWindowViewModel, "mainWindowViewModel");

			mainWindowViewModel.IsAutoStartEnabled = this.attacherAutoStartManager.IsApplicationAutoStartEnabled();

			if (Properties.Settings.Default.FirstRun)
			{
				Properties.Settings.Default.FirstRun = false;
				Properties.Settings.Default.Save();

				if (!mainWindowViewModel.IsAutoStartEnabled)
				{
					this.attacherAutoStartManager.ChangeApplicationAutoStart();
					mainWindowViewModel.IsAutoStartEnabled = this.attacherAutoStartManager.IsApplicationAutoStartEnabled();
				}
			}
		}
	}
}
